package OperationSystem.day1206.OutputStream;

import java.io.*;

public class OutputStreamDemo {
    public static void main(String[] args) throws IOException {
        try (OutputStream os = new FileOutputStream("使用outputStreamPrintWriter.txt")) {
            //读入字节流
            /*   1、write(),参数为int b
            os.write('H');
            os.write('e');
            os.write('l');
            os.write('l');
            os.write('o');
            os.write('\r');
            os.write('\n');
            os.flush();
        */
            /*  2、write(),参数为byte[] b,int off,int len
        byte[] buffer={'H','e','l','l','o',0x0D,0x0A};
        os.write(buffer,0,buffer.length);
        os.flush();
           */

            /*
            //如果要读入字符流呢？
            String s = "你好中国";
            //只能把String类型的字符串转化为(编码为) byte类型的数组
            byte[] buffer = s.getBytes("GBK");
            os.write(buffer,0,buffer.length);
            os.flush();
            */

            /*
            try (Writer writer=new OutputStreamWriter(os,"UTF-8")){
                writer.append("你好中国");
                writer.flush();
            }*/
            try (PrintWriter writer=new PrintWriter(new OutputStreamWriter(os,"UTF-8"))){
                for(int i=0;i<10;i++){
                    writer.printf("%02d:你好世界%n",i);
                }
                writer.flush();
            }
        }
    }
}
